package com.jic.interaction.JDVOP.controller;

import com.jic.interaction.JDVOP.common.utils.RestResult;
import com.jic.interaction.JDVOP.model.vo.request.*;
import com.jic.interaction.JDVOP.model.vo.response.*;
import com.jic.interaction.JDVOP.service.ProductService;
import com.jic.product.manage.response.ProductResponse;
import com.jic.product.rest.response.ProductCategoryRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(value="JD商品Api", tags = "JD商品Api", description = "ProductController")
@RestController
@RequestMapping("api/product/")
public class ProductController {

    @Resource
    private ProductService productService;

    @ApiOperation("查询商品池编辑")
    @PostMapping("getPageNum")
    @ResponseBody
    private RestResult<List<ProductResultResponse>> getPageNum(@RequestBody ProductResultRequest result) throws Exception {
        List<ProductResultResponse> value = productService.queryCommodityPools(result.getToken());
        if (value.equals(null)){
            return RestResult.error(null,"9999","查询商品池编辑失败");
        }
        return RestResult.success(value,"0000", "查询成功");
    }

    @ApiOperation("查询池内商品编号")
    @PostMapping("getSkuByPage")
    @ResponseBody
    private RestResult<List<ProductCodeResponse>> getSkuByPage(@RequestBody ProductResultRequest result) throws Exception {
        List<ProductCodeResponse> value = productService.queryProductCode(result);
        if (value == null){
            return RestResult.error(null,"9999","查询池内商品编号失败");
        }
        return RestResult.success(value,"0000","查询成功");
    }


    @ApiOperation("查询商品详情")
    @PostMapping("getDetail")
    @ResponseBody
    private RestResult<MatterProductRequest> getProductDetail(ProductDetailsRequest request) throws Exception {
        MatterProductRequest value = productService.getProductDetails(request);
        if (value==null){
            return RestResult.error(null,"9999","查询商品详情失败");
        }
        return RestResult.success(value,"0000","查询成功");
    }

    @ApiOperation("获取商品图片")
    @PostMapping("skuImage")
    private RestResult<ProductImageResponse> getProductSkuImage(ProductImageRequest request) throws Exception {
        ProductImageResponse value = productService.getProductSkuImage(request);
        if (value == null) {
            return RestResult.error(null, "9999", "获取商品图片失败");
        }
        return RestResult.success(value, "0000", "查询成功");
    }

    @ApiOperation("获取商品状态，是否上下架")
    @PostMapping("skuState")
    @ResponseBody
    private RestResult<List<ProductStatusResponse>> getProductStatus(@RequestBody @Valid ProductStatusRequesr request) throws Exception {
        List<ProductStatusResponse> value = productService.getProductStatus(request);
        if (value!=null){
            return RestResult.error(null,"9999","获取商品状态失败");
        }
        return RestResult.success(value,"0000","查询成功");
    }

    @ApiOperation("验证商品可售性")
    @PostMapping("check")
    @ResponseBody
    private RestResult<List<ProductCheckResponse>> availableSex(@RequestBody ProductCheckRequest request) throws Exception {
        List<ProductCheckResponse> response = productService.availableSex(request);
        if (response==null){
            return RestResult.error(null,"9999","验证商品可售性失败");
        }
        return RestResult.success(response,"0000","查询成功");
    }

    @ApiOperation("查询商品区域购买限制")
    @PostMapping("checkAreaLimit")
    @ResponseBody
    private RestResult<ProductAstricetResponse> checkAreaLimit(@RequestBody ProductAastrictRequest request){
        ProductAstricetResponse response = productService.checkAreaLimit(request);
        if (response==null){
            return RestResult.error(null,"9999","查询商品区域购买限制失败");
        }
        return RestResult.success(response,"0000","查询成功");
    }

    @ApiOperation("查询赠品信息")
    @PostMapping("getSkuGift")
    @ResponseBody
    private RestResult<List<ProductGiftResponse>> getSkuGift( ProductGiftRequest request){
        List<ProductGiftResponse> response = productService.getSkuGift(request);
        if(response == null){
            return RestResult.error(null,"9999","本人真在通宵加班中");
        }
        return RestResult.success(response,"0000","查询成功");
    }


    @ApiOperation("查询商品延保")
    @PostMapping("getYanbaoSku")
    @ResponseBody
    private RestResult<ProductYanBaoRequest> getYanBao(@RequestBody ProductYanBaoRequest request){
        ProductGiftResponse response = productService.getYanBao(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }


    @ApiOperation("验证货到付款")
    @PostMapping("getIsCod")
    @ResponseBody
    private RestResult<Boolean> getIsCod(@RequestBody ProductPaymentRequest request){
        Boolean  result=productService.getIsCod(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }

    @ApiOperation("获取商品信息")
    @PostMapping("search")
    @ResponseBody
    private RestResult<List<ProductSearchResponse>> search(@RequestBody ProductSearchRequest request){
        List<ProductSearchResponse>  result=productService.search(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }

    @ApiOperation("查询同类商品")
    @PostMapping("getSimilarSku")
    @ResponseBody
    private RestResult<List<ProductSameParametersResponse>> querySameParameters(@RequestBody ProductSimilarSkuRequest request){
        List<ProductSameParametersResponse>  result=productService.querySameParameters(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }

    @ApiOperation("查询分类信息")
    @PostMapping("getCategory")
    @ResponseBody
    private RestResult<List<ProductCategoryRestResponse>> getCategory(@RequestBody ProductCategoryRequest request){
        List<ProductCategoryRestResponse>  result=productService.getCategory(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }

    @ApiOperation("查询分类列表")
    @PostMapping("getCategorys")
    @ResponseBody
    private RestResult<List<ProductCategorysResponse>> getCategorys(@RequestBody ProductCategorysRequest request){
        List<ProductCategoryRestResponse>  result=productService.getCategorys(request);
        return RestResult.error(null,"9999","本人真在通宵加班中");
    }



}
